<?php 
ob_implicit_flush(); 
set_time_limit(0); 

$address        = "localhost";//换成你自己的地址 
$port           = 9999; 

if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false) 
echo "错误(socket_create)：".socket_strerror(socket_last_error())."<br />"; 

if(socket_bind($socket,$address,$port) == false) 
echo "错误(socket_bind)：".socket_strerror(socket_last_error())."<br />"; 

if(socket_listen($socket) == false) 
echo "错误(socket_listen)：".socket_strerror(socket_last_error())."<br />"; 

/* 
After the socket socket has been created using socket_create() and bound to a name with socket_bind(),  
it may be told to listen for incoming connections on socket.  
*/ 

while(true){ 
        if(($msgSocket = socket_accept($socket)) == false)
        { 
                echo "错误(socket_accept)：".socket_strerror(socket_last_error())."<br />"; 
                break; 
        }
        $command1 = "welcome"; 
        socket_write($msgSocket,$command1,strlen($command1)); 
        socket_close($msgSocket); 
} 
socket_close($socket); 
?> 

